package cn.jhc.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.bean.ShopBean;
import cn.jhc.dao.ShopDAO;

@WebServlet("/houtaideletelistgoods.do")
public class Houtai_DeleteListgoodsServlet extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		List<ShopBean> listgoods = new ArrayList<ShopBean>();
		String user = req.getParameter("user");
		String id =req.getParameter("id");
		int Id = Integer.parseInt(id);
		String List_id =req.getParameter("List_id");
		int list_id = Integer.parseInt(List_id);
		String date = req.getParameter("date");
		String time = req.getParameter("time");
		double price=Double.parseDouble(req.getParameter("price"));
		int amount=Integer.parseInt(req.getParameter("amount"));
		String datetime = date + " " + time;
		ShopDAO dao = null;
		dao = new ShopDAO();

		try {
			if (dao.AdminChecklistgoods(user, datetime).size() > 1){
				dao.deletelistgoods(Id, datetime,price,amount);
				System.out.println("1");
			}
			else{
				dao.Admindeletelist(list_id, datetime);
				System.out.println("2....."+list_id);
			}
			listgoods = dao.Checklistgoods(user, datetime);
		} catch (Exception e) {
			e.printStackTrace();
		}if(listgoods.size()==0)
		{
			req.setAttribute("date", datetime);
			RequestDispatcher dispatcher = req.getRequestDispatcher("/adminchecklist.jsp?Page=1&judgment=F&judgment2=T");
			dispatcher.forward(req, resp);
		}else{
		req.setAttribute("date", date);
		req.setAttribute("time", time);
		req.setAttribute("user", user);
		RequestDispatcher dispatcher = req
				.getRequestDispatcher("/adminchecklistgoods.jsp?Page=1");
		dispatcher.forward(req, resp);}
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
}